﻿using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TestConsole;

namespace ReForm.Shared.Pages
{
    public partial class FormParser
    {
        private string formHtml;

        private List<FormControlBase> controls;

        private JsGen gen = new JsGen();

        protected override void OnInitialized()
        {
            base.OnInitialized();
            var filePath = "TestForm.txt";
            formHtml = File.ReadAllText(filePath);
        }

        private string JsCode;

        /// <summary>
        /// 点击解析
        /// </summary>
        private void OnClickParse()
        {
            FormHtmlPaser paser = new FormHtmlPaser();
            controls = paser.GetControls(formHtml);
        }

        private void OnClickGenJs()
        {
            if (controls!=null)
            {
                JsCode= gen.GetJs(controls);

                InfoSaver saver = new InfoSaver();
                saver.SaveToFile(InfoSaver.TempFileName, controls);
            }
        }

        private void Refresh()
        {

        }
    }
}
